<?php
class Library_Model_NhomVanBanMapper extends Library_Model_DataMapperAbstract
{
	private static $_instance = null;
	private $_paginator = null ;
	
	public function searchNhomVanBanById($id)
	{
		$db = $this->getDb();
		$selectNhom = $db->select()
				->from('tbl_nhomvanban')
				->where('MaNhom = ?',$id);
		$nhom = $db->fetchRow($selectNhom);
	
		return $this->_populate($nhom);
	
	}
	public function nhomvanbanList()
	{
		$db = $this->getDb();
		$selectNhom = $db->select()
						->from('tbl_nhomvanban');
		$nhoms = $db->fetchAll($selectNhom);
	
		$nhomObjArray = array();
		foreach($nhoms as $nhom){
			$nhomObjArray[] = $this->_populate($nhom);
		}
	
		return $nhomObjArray;
	}
	
	public function _populate($data){
		$obj = new Library_Model_NhomVanBan();
		$obj->setId($data['MaNhom']);
		$obj->setTennhom($data['TenNhom']);
		
		
		return $obj;		
	}
	
	protected function _insert(Library_Model_DomainObjectAbstract $obj){	
		$db = $this->getDb();
		$data =array(
				'MaNhom' => $obj->getId(),
				'TenNhom' => $obj->getTennhom()
					
				);
		$db->insert('tbl_nhomvanban',$data);
	}
	protected function _update(Library_Model_DomainObjectAbstract $obj){
		
		$db = $this->getDb();
		$data =array(
				'MaNhom' => $obj->getId(),
				'TenNhom' => $obj->getTennhom()
				);
		$where = $db->quoteInto('MaNhom = ?', $obj->getId());
		$db->update('tbl_nhomvanban',$data,$where);
	}
	
	public function delete($id)
	{
		$db = $this->getDb();
		$where = $db->quoteInto('MaNhom = ?',$id);
		$db->delete('tbl_nhomvanban',$where);
	}
	public static function getInstance(){
		if(!isset(self::$_instance)){
			$c = __CLASS__;
			self::$_instance = new $c;
		}
		return self::$_instance;
	}
	
	}